import { http } from '@/utils/request';



export function fetchStoreAddress(storeId:string,params: any) {
  return http.request({
    url: "/store/address/page/"+storeId,
    method: "GET",
    params,
  });
}


/**
 * 设置默认地址
 * @param params 地址参数
 */
export function setAddressDefault(params: any) {
  return http.request({
    url: "/member/address",
    method: "PUT",
    data: params,
    header: { "content-type": "application/x-www-form-urlencoded" },
  });
}

export function getDefaultAddress() {
  return http.request({
    url: `/member/address/get/default`,
    method: "GET",
  });
}


/**
 * 获取物流公司
 */
export function getLogistics() {
  return http.request({
    url: "/other/logistics",
    method: "GET",
    params: { pageNumber: 1, pageSize: 200, disabled: "OPEN" },
  });
}


/**
 * 获取收货地址列表
 * @returns {AxiosPromise}
 */
export function getAddressList(data: any) {
  return http.request({
    url: "/member/address/list",
    method: "GET",
    params: data,
  });
}

/**
 * 添加收货地址
 * @param params 地址参数
 * @returns {AxiosPromise}
 */
export function addAddress(data: any) {
  return http.request({
    url: "/member/address",
    method: 'POST',
    header: { "content-type": "application/x-www-form-urlencoded" },
    data: data,
  });
}
/**
 * 编辑地址
 * @param id 地址ID
 * @param params 地址参数
 * @returns {AxiosPromise}
 */
export function editAddress(params: any) {
  return http.request({
    url: `/member/address`,
    method: 'PUT',
    header: { "content-type": "application/x-www-form-urlencoded" },
    data: params,
  });
}
/**
 * 删除收货地址
 * @param id
 */
export function deleteAddress(id: string | number) {
  return http.request({
    url: `/member/address/delById/${id}`,
    method: "DELETE",

  });
}

/**
 * 根据ID获取会员收件地址
 * @param id
 */
export function getAddressDetail(id: string | number) {
  return http.request({
    url: `/member/address/get/${id}`,
    method: "GET",
  });
}
/**
 * 设置默认地址
 */
export function getAddressDefault() {
  return http.request({
    url: `/member/address/get/default`,
    method: "GET",
  });
}

/**
 * 设置收货地址ID
 * @param addressId
 */
export function setAddressId(addressId: string | number, way: string) {
  return http.request({
    url: `/trade/carts/shippingAddress?shippingAddressId=${addressId}&way=${way}`,
    method: "GET",
  });
}
